/**
 * @Description 鼠标悬浮图片放大效果(兼容IE)
 * @author w404
 * @DOM
 * @CSS
 * @Usage
 *      $(".J_suns").scale(1.1);
 * @options
 *      speed: 500, //动画执行时间，单位为毫秒，默认为500
 *      multiple: 1.1, // 放大或缩小倍数，默认1.1
 *      mgLeft: 0, // 图片左边距，默认为0
 *      mgTop: 0 // 图片上边距，默认为0
 * @compatibility IE7,8,9正常使用
 */

;(function($) {
    $.fn.scale = function(options) {
        var defaults = {
                speed: 500, //动画执行时间，单位为毫秒，默认为500
                multiple: 1.1, // 放大或缩小倍数，默认1.1
                mgLeft: 0, // 图片左边距，默认为0
                mgTop: 0 // 图片上边距，默认为0
            },
            opts = $.extend({}, defaults, options);

        this.each(function(i) {
            if (!!!isIE()) return;
            var _this = $(this),
                _img = _this.find('img'),
                _speed = opts.speed,
                _multiple = opts.multiple,
                _left = opts.mgLeft,
                _top = opts.mgTop,
                imgWid = _this.width(),
                imgHei = _this.height(); //变量初始化
            _this.hover(function() {
                _img.stop(true, true);
                var imgWid2 = 0,
                    imgHei2 = 0,
                    imgWid2 = imgWid * _multiple,
                    imgHei2 = imgHei * _multiple;
                _img.animate({
                    "width": imgWid2,
                    "height": imgHei2,
                    "margin-left": (imgWid - imgWid2) / 2,
                    "margin-top": (imgHei - imgHei2) / 2
                }, _speed);
            }, function() {
                _img.stop().animate({
                    "width": imgWid,
                    "height": imgHei,
                    "margin-left": 0,
                    "margin-top": 0
                }, _speed);
            });
        });

        // 判断是否是IE浏览器
        function isIE() {
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
            var isOpera = userAgent.indexOf("Opera") > -1;
            return userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera ? true : false
        }
    }
})(jQuery)